package com.bilibili.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bilibili.dao.UserInfoMapper;
import com.bilibili.domain.JsonResponse;
import com.bilibili.domain.entity.UserInfo;
import com.bilibili.domain.exception.ConditionException;
import com.bilibili.service.UserInfoService;
import org.apache.commons.lang3.StringUtils;

import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;

/**
* @author www
* @description 针对表【t_user_info(用户基本信息表)】的数据库操作Service实现
* @createDate 2024-06-02 19:58:42
*/
@Service
public class UserInfoServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo>
    implements UserInfoService {
    @Resource
    private UserInfoMapper userInfoMapper;
    LambdaQueryWrapper<UserInfo> wrapper = new LambdaQueryWrapper<>();

    @Override
    public UserInfo getByUserId(Long userId) {
        wrapper.eq(UserInfo::getUserId,userId);
        return userInfoMapper.selectOne(wrapper);
    }

    @Override
    public Integer updateUserInfo(UserInfo userInfo) {
        userInfo.setUpdateTime(new Date());
        if (StringUtils.isAnyBlank(userInfo.getNick(),userInfo.getGender()))
        {
            throw new ConditionException("用户信息缺失！");
        }
        return userInfoMapper.updateById(userInfo);
    }
}




